package reflect;

import java.lang.reflect.Constructor;

public class Test {
    public static void main(String[] args) throws Exception{
        // 获取无参类对象
        Class cls = Class.forName("reflect.Student");
        Object obj = cls.newInstance();
        System.out.println(obj);

        // 有参类对象，通过constructor构造器
        Class cls2 = Class.forName("reflect.Student");
        Constructor constructor = cls2.getConstructor(String.class, int.class,char.class);
        Object obj2 = constructor.newInstance("张三", 18, '男');
        System.out.println(obj2);
    }
}
